import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class code3 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int ret = 0;
        for(int i =a;i<=b;i++) {
            if(check(i)) ret++;
        }
        System.out.println(ret);
    }
    private static boolean check(int x) {
        char[] ss = String.valueOf(x).toCharArray();
        int n = ss.length;
        for(int i=0;i<n;i++) {
            for(int j=0;j<n;j++) {
                if(ss[i]!='0' && i!=j) {
                    int k = (ss[i]-'0') * 10 + (ss[j]-'0');
                    if(prim(k)) return true;
                }
            }
        }
        return false;
    }

    private static boolean prim(int k) {
        if(k < 2) return false;//
        for(int i=2;i<=Math.sqrt(k);i++) {//有=,不然9就成质数了
            if(k % i == 0) {
                return false;
            }
        }
        return true;
    }
}